import { observable } from 'mobx'

const formStore = observable({
  list: [{
    value: '1',
    text: '男',
    checked: true
  },
  {
    value: '0',
    text: '女',
    checked: false
  },],
  list1: [{
    value: '1',
    text: '有',
    checked: true
  },
  {
    value: '0',
    text: '无',
    checked: false
  },],
  list2: [{
    value: '1',
    text: '有',
    checked: true
  },
  {
    value: '0',
    text: '无',
    checked: false
  },],
  levelList: ['初级', '中级', '高级'],
  dateSel: '2018-04-22',
  workHistory: [
  ],
  education: [
  ],
  trainHistory: [
  ],
  // 修改时间
  onDateChange(value) {
    this.dateSel = value;
  },
  //修改工作历史时间
  onWorkHistoryDateChange(i, isBeginTime, e) {
    if (isBeginTime) {
      this.workHistory[i].beginTime = e.detail.value;
    } else {
      this.workHistory[i].finishTime = e.detail.value;
    }
  },
  //添加工作经历
  addOrDeleteWorkHistory(isAdd) {
    if (isAdd) {
      this.workHistory.push({
        beginTime: '2018-04-22',
        finishTime: '2018-04-22',
        dept: '部门',
        company: '任职单位',
        num: 'xxx-xxxxxxxxxxx',
        season: '离职原因',
        money: '薪资水平'
      })
    } else {
      if (this.workHistory.length !== 0) {
        this.workHistory.pop();
      }
    }
  },
  //修改教育经历时间
  onEducationHistoryDateChange(i, isBeginTime, e) {
    if (isBeginTime) {
      this.education[i].beginTime = e.detail.value;
    } else {
      this.education[i].finishTime = e.detail.value;
    }
  },
  //添加教育经历
  addOrDeleteEducationList(isAdd) {
    if (isAdd) {
      this.education.push({
        beginTime: '2018-04-22',
        finishTime: '2018-04-22',
        school: '学校',
        profession: '专业',
        level: '学历'
      })
    } else {
      if (this.education.length !== 0) {
        this.education.pop();
      }
    }
  },
  onLevelChange(e) {
    this.level = this.levelList[e.detail.value]
  },

  //修改培训经历时间
  onTrainHistoryDateChange(i, e) {
    this.trainHistory[i].beginTime = e.detail.value;
  },
  //添加培训经历
  addOrDeleteTrainList(isAdd) {
    if (isAdd) {
      this.trainHistory.push({
        beginTime: '2018-04',
        skill: '职位/技能名称',
        level: '职称/技能等级',
        code: '证书编号'
      })
    } else {
      if (this.trainHistory.length !== 0) {
        this.trainHistory.pop();
      }
    }
  },
  //验证
  valid(e) {
    let invalid = false;
    const {
      birthplace,
      currentSalary,
      expectedSalary,
      familyphoneNumber,
      id,
      liveAdd,
      mail,
      name,
      phone,
      post,
      providentFund,
      sex,
      socialCard,
      workYear,
    } = e.detail.value;
    if (!currentSalary || !familyphoneNumber || !mail || !name || !phone || !post || !providentFund || !socialCard || !workYear){
      invalid = true;
    };
    if(this.workHistory.length || this.education.length){
      invalid = true;
    }
    return invalid;
  },
  validTime(beginTime,finishTime){
    if(beginTime>finishTime)return false;
    return true;
  }
})
export default formStore